package xhtml2pdf;

import java.util.Vector;

import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;

/** use singleton pattern*/
public class TableCreator{
	private int colNum = 0;
	private boolean isFirstRow;
	private PdfPTable table = null;
	private Vector<PdfPCell> firstRowCells = null;
	
	
	public TableCreator(){
		init();
	}
	public void init(){
		isFirstRow = true;
		colNum = 0;
		firstRowCells = new Vector<PdfPCell>();
	}
	public void close(){
		init();
	}
	
	public void addColNum(){
		colNum++;
	}
	public void addColNum(int num){
		colNum += num;
	}
	
	public void addCell(PdfPCell cell){
		if(isFirstRow){
			firstRowCells.addElement(cell);
		}else{
			table.addCell(cell);
		}
	}
	
	public void createTable(){
		table = new PdfPTable(colNum);
		for (int i = 0; i < firstRowCells.size() ; i++) {
			table.addCell((PdfPCell)firstRowCells.get(i));
		}
		table.setWidthPercentage(100f);
	}
	public PdfPTable getTable(){
		return table;
	}
	
	public boolean isFirstRow(){
		return isFirstRow;
	}
	public void setIsFirstRow(boolean flag){
		isFirstRow = flag;		
	}
	
	 
	
	
}
